package dhadi.use.swing;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
import java.util.List;

import dhadi.model.Node;

public class NodeUi 
{
	final private int nodeWidth = 10;
	private Layout layout;
	private Point p = new Point(0,0);
	public Node node;
	final private Rectangle r = new Rectangle(p.x,p.y,nodeWidth,nodeWidth);
	
	public boolean isPossibleNode = false;
	public boolean isCurrentNode = false;
	public NodeUi(int x, int y, Node node, Layout layout)
	{
		this.setLocation(x,y);
		this.node = node;
		this.layout = layout;
	}
	
	public void setLocation(int x, int y)
	{
		this.p.x = x;
		this.p.y = y;
		r.x = p.x - nodeWidth/2;
		r.y = p.y - nodeWidth/2;
	}
	
	public Point getLocation()
	{
		return this.p;
	}
	
	public List<NodeUi> getAdjusantEmptyNodes() {
		return this.layout.convertToUi(this.node.getAdjusantEmptyNodes());		
	}
	
	public void draw(Graphics g)
	{
		Color oldColor = g.getColor();
		g.setColor(Color.LIGHT_GRAY);
		
		if (isCurrentNode)
		{
			g.setColor(Color.RED);			
		}
		else if (this.isPossibleNode)
		{
			g.setColor(Color.YELLOW);
		}
		
		g.fillOval(r.x, r.y, r.width, r.width);
		g.setColor(oldColor);
	}
	
	@Override
	public String toString() {
		return "NodeUi [node=" + node + ", p=" + p + "]";
	}	
}
